package jay.sendsms;

import android.app.Activity;
import android.app.PendingIntent;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.widget.EditText;

public class SMSsendActivity extends Activity {
	/** Called when the activity is first created. */
	String number,message;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
	}
	public void SMSsend(View v)

	{ 
		EditText t1=(EditText)findViewById(R.id.ed1);
		EditText t2=(EditText)findViewById(R.id.ed2);
		number=t1.getText().toString();
		message=t2.getText().toString();
//		PendingIntent pi = PendingIntent.getActivity(this, 0, new Intent(this, MyGPSActivity.class ), 0); 
		SmsManager sms = SmsManager.getDefault(); //
		sms.sendTextMessage("tel: " + number, null, message, null, null); 
	} 
	
	public void readSMS(View v){ 
		EditText t3=(EditText)findViewById(R.id.ed3);
		Cursor cursor = getContentResolver().query(Uri.parse("content://sms/inbox"), null, null, null, null); 
		cursor.moveToFirst(); 
		String msgData = ""; 
		do{ 
			msgData += "\n"; 
			for(int idx=0;idx<cursor.getColumnCount();idx++) 
			{ 
				if("body".equalsIgnoreCase(cursor.getColumnName(idx))){
				msgData += " " + cursor.getColumnName(idx) + ":" + cursor.getString(idx);
				}
			}
			if(msgData.length()>=300){ 
				break; 
			} 
		} 
		while(cursor.moveToNext()); 
		t3.setText(msgData);
	}
}
